package com.ruoyi.energy.controller;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.domain.JiMuReportResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.NyTransAllowCheck;
import com.ruoyi.energy.domain.vo.NyTransAllowDetialVOR;
import com.ruoyi.energy.service.INyTransAllowCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 变压器监测Controller
 *
 * @author cjie
 * @date 2022-03-07
 */
@Api(tags = " 变压器监测")
@RestController
@RequestMapping("/nyTransAllowCheck")
public class NyTransAllowCheckController extends BaseController {
    @Autowired
    private INyTransAllowCheckService nyTransAllowCheckService;

    /**
     * 查询变压器监测列表
     */
    @ApiOperation(value="查询变压器监测列表", notes="查询变压器监测列表")
    @PreAuthorize(hasPermi = "energy:nyTransAllowCheck:list")
    @GetMapping("/list")
    public TableDataInfo list(NyTransAllowCheck nyTransAllowCheck) {
        startPage();
        List<NyTransAllowCheck> list = nyTransAllowCheckService.selectNyTransAllowCheckList(nyTransAllowCheck);
        return getDataTable(list);
    }

    /**
     * 导出变压器监测列表
     */
    @ApiOperation(value="导出变压器监测列表", notes="导出变压器监测列表")
    @PreAuthorize(hasPermi = "energy:nyTransAllowCheck:export")
    @Log(title = "变压器监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NyTransAllowCheck nyTransAllowCheck) throws IOException {
        List<NyTransAllowCheck> list = nyTransAllowCheckService.selectNyTransAllowCheckList(nyTransAllowCheck);
        ExcelUtil<NyTransAllowCheck> util = new ExcelUtil<NyTransAllowCheck>(NyTransAllowCheck.class);
        util.exportExcel(response, list, "变压器监测数据");
    }
    /**
     * 获取变压器监测详细信息
     */
    @ApiOperation(value="获取变压器监测详细信息", notes="获取变压器监测详细信息")
    @PreAuthorize(hasPermi = "energy:nyTransAllowCheck:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(nyTransAllowCheckService.selectNyTransAllowCheckById(id));
    }

    /**
     * 新增变压器监测
     */
    @ApiOperation(value="新增变压器监测", notes="新增变压器监测")
    @PreAuthorize(hasPermi = "energy:nyTransAllowCheck:add")
    @Log(title = "变压器监测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NyTransAllowCheck nyTransAllowCheck) {
        return toAjax(nyTransAllowCheckService.insertNyTransAllowCheck(nyTransAllowCheck));
    }

    /**
     * 根据transId查询 空开申请列表，返回Map<enName,List<></>></>
     */
    @ApiOperation(value="小程序空开监测批量提交", notes="小程序空开监测批量提交")
    @PreAuthorize(hasPermi = "energy:nyTransAllowCheck:add")
    @PostMapping(value = "/wx/savelist")
    public AjaxResult saveAllowDetailList(@RequestBody NyTransAllowDetialVOR map) {
//        String curLoad = map.get("curLoad").toString();
//        JSONArray objects = JSONUtil.parseArray((String)map.get("curList"));
////        List<NyTransAllowDetailVO> curList = JSONUtil.toList(objects, NyTransAllowDetailVO.class);
//        List<NyTransAllowDetailVO> curList = (List<NyTransAllowDetailVO>)map.get("curList");
        return AjaxResult.success(nyTransAllowCheckService.batchInsertNyTransAllowDetailVO(map));
    }

    /**
     * 修改变压器监测
     */
    @ApiOperation(value="修改变压器监测", notes="修改变压器监测")
    @PreAuthorize(hasPermi = "energy:nyTransAllowCheck:edit")
    @Log(title = "变压器监测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NyTransAllowCheck nyTransAllowCheck) {
        return toAjax(nyTransAllowCheckService.updateNyTransAllowCheck(nyTransAllowCheck));
    }

    /**
     * 删除变压器监测
     */
    @ApiOperation(value="删除变压器监测", notes="删除变压器监测")
    @ApiImplicitParam(name = "ids", value = "变压器监测ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:nyTransAllowCheck:remove")
    @Log(title = "变压器监测", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(nyTransAllowCheckService.deleteNyTransAllowCheckByIds(ids));
    }

    /**
     * 新增变压器监测
     */
    @ApiOperation(value="变压器监测报表", notes="变压器监测报表")
    @Log(title = "变压器监测报表", businessType = BusinessType.INSERT)
    @GetMapping("/report")
    public JiMuReportResult report(NyTransAllowCheck nyTransAllowCheck) {
        nyTransAllowCheck.setTransName("6#箱变");
        nyTransAllowCheck.setCheckMonth(DateUtil.parse("2022-05-31"));
        List<NyTransAllowCheck> results = nyTransAllowCheckService.selectNyTransAllowCheckList(nyTransAllowCheck);
        return JiMuReportResult.success(results);
    }

}
